/*
 * @Author: 家
 * @QQ: 203118908
 * @QQ交流群: 1019208967
 * @bilibili: 晓宇小凡
 * @简书: 晓凡晓宇
 * @versioin: 1.0
 * @Date: 2020-06-14 19:51:56
 * @LastEditTime: 2020-06-21 16:34:32
 * @LastEditors: 家
 * @Description:
 * @FilePath: \temp\剪贴板事件监听.js
 * @学习格言: 即用即学, 即学即用
 * @参考链接: https://blog.csdn.net/zhaizu/article/details/70154301
 */

// 原来的java
/*
private void registerClipEvents() {

  final ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

  manager.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
      @Override
      public void onPrimaryClipChanged() {

          if (manager.hasPrimaryClip() && manager.getPrimaryClip().getItemCount() > 0) {

              CharSequence addedText = manager.getPrimaryClip().getItemAt(0).getText();

              if (addedText != null) {
                  Log.d(TAG, "copied text: " + addedData);
              }
          }
      }
  });
}
*/

let manager = context.getSystemService(context.CLIPBOARD_SERVICE);

manager.addPrimaryClipChangedListener(
  new android.content.ClipboardManager.OnPrimaryClipChangedListener({
    onPrimaryClipChanged: function () {
      if (manager.hasPrimaryClip() && manager.getPrimaryClip().getItemCount() > 0) {
        let addedText = manager.getPrimaryClip().getItemAt(0).getText();
        if (addedText != null) {
          log("copied text: " + addedText);
        }
      }
    },
  })
);
setInterval(() => {}, 1000);
